﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebUtils;

namespace OAuth.AuthLocations
{
    public sealed class PostParameter : AuthInfoLocation
    {
        private static PostParameter instance;
        public static PostParameter Instance
        {
            get
            {
                if (instance == null)
                    instance = new PostParameter();
                return instance;
            }
        }


        private PostParameter()
        {
        }

        public override string Name { get { return "POST params, application/x-www-form-urlencoded"; } }

        public override ISignedWebRequest CreateSignedRequest(IUnsignedWebRequest pUnsignedWebRequest, IEnumerable<UnEncodedURLParameter> pOAuthParameters)
        {
            return new DefaultSignedWebRequest() 
            {
                Address = pUnsignedWebRequest.Address,
                GetParameters = pUnsignedWebRequest.GetParameters,
                Headers = pUnsignedWebRequest.Headers.Concat(new Parameter[] { new Parameter() { Key = "Content-Type", Value = "application/x-www-form-urlencoded" } }),
                UnsignedWebRequest = pUnsignedWebRequest,
                Verb = pUnsignedWebRequest.Verb,
                PostParameters = pUnsignedWebRequest.PostParameters.Concat(pOAuthParameters)
            };
        }
    }
}
